/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './product';
import * as API from './types';

/** 分页查询产品信息 GET /product */
export function productGetProductPageQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.ProductGetProductPageParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.productGetProductPage(queryKey[1] as typeof options);
    },
    queryKey: ['productGetProductPage', options],
  });
}

/** 新增产品信息 POST /product */
export function useProductAddProductMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productAddProduct,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 删除产品信息 DELETE /product */
export function useProductDeleteProductMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productDeleteProduct,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 查询产品信息详情 GET /product/${param0} */
export function productGetProductDetailsQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.ProductGetProductDetailsParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.productGetProductDetails(queryKey[1] as typeof options);
    },
    queryKey: ['productGetProductDetails', options],
  });
}

/** 新增并提交审核产品信息 POST /product/add_submit */
export function useProductAddAndSubmitProductMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productAddAndSubmitProduct,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 编辑产品信息 PUT /product/edit */
export function useProductEditProductMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productEditProduct,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 编辑并提交审核产品信息 PUT /product/edit_submit */
export function useProductEditAndSubmitProductMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productEditAndSubmitProduct,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 提交审核产品信息 POST /product/submit */
export function useProductSubmitProductMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.productSubmitProduct,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}
